Release 10.1A: OpenEdge Development:
ProDataSets
Using the error attributes in the sample procedures
In this section, you will add a simple validation check to the
updateOrder.pprocedure, set theERRORandREJECTEDflags and theERROR-STRING, and check for these back in the window procedure.
![]()
To add the validation check:
- In
updateOrder.p, retrieve the after-table row for each before-table row in the change ProDataSet. Add this dynamicFINDstatement at the top of theFOR EACHttOlineBeforeblock:
Remember that even though the change ProDataSet is created as a dynamic ProDataSet in the window procedure,
updateOrder.preceives it into a static definition, so you can reference both the before- and after-table buffers by their static names.- Now that you have both versions of the row, compare the price and generate an
ERROR-STRINGif the price has been increased by more than 10 percent. For example:
Here you are first setting the
ERRORattribute for the whole change ProDataSet. This makes it easy to tell back in the calling procedure whether there were any errors.Next, you set
ERRORfor the individual buffer along with theREJECTEDattribute to signal toMERGE-CHANGESthat this update did not make it into the database.Then you construct an error message and attach it to the buffer in error. The text of the message, when assembled, will be something like:
If the validation check does not fail, the
ELSEkeyword invokes theSAVE-ROW-CHANGESmethod to save the changes to the database. Note that this is one kind of error you can generate, one that is detected by your own code. TheSAVE-ROW-CHANGESmethod itself could also generate errors if a native Progress error results from the change. In this case, Progress setsERRORat all levels but notREJECTEDor theERROR-STRING.- Change
dsOrderWinUpd.wto check for the error.- Add an editor control to the bottom of the window, called
cStatus.- Give it a vertical scrollbar but no horizontal scrollbar.
- Make it enabled but read-only.
- Make it tall enough to display one or two rows, as shown:
![]()
- In the
CHOOSE OF BtnSavetrigger, add this block of code after you runupdateOrder.p:
This first checks the
ERRORattribute on the ProDataSet as a whole. This is why you set this attribute at this level, so that you know at once that there was an error in one of the updates.To locate each error, you need to create a dynamic query for the
ttOlinebuffer, prepare it, open it, and walk through all its rows. For each one with theERRORstatus, you append theERROR-STRINGmessage to the editor text, with a line feed in between each one.After closing and deleting the query, you display the status string.
Following this, the code already runs
MERGE-CHANGESon the ProDataSet. When this happens,MERGE-CHANGESchecks theREJECTEDattribute of each row and restores the original row to the values it had before the update. Once again, this might not always be the behavior you want, but we use it here to illustrate whatMERGE-CHANGESdoes for you.- Rerun the window to see the effect of your changes.
- Select an
Orderand change thePriceof one or more of itsOrderLinesto be more than 10% higher than before:
![]()
- Select Save Changes to try to save these invalid changes:
![]()
The error strings are displayed in the status editor, and the changed prices have been rolled back in the
ttOlinetable and its browse. Any successful updates would be displayed, along with the updatedExtended Price, in the browse as well.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |